//
//  GYLockListTableViewCell.m
//  LockManagement
//
//  Created by apple on 2018/7/27.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

static NSString *lockListCellIdentifier = @"lockListCellIdentifier";

#import "GYLockListTableViewCell.h"

@interface GYLockListTableViewCell()


@property (weak, nonatomic) IBOutlet UILabel *areaLable;
@property (weak, nonatomic) IBOutlet UILabel *latLable;

@property (weak, nonatomic) IBOutlet UIButton *routeBtn;
@property (weak, nonatomic) IBOutlet UIButton *applyBtn;
@property (weak, nonatomic) IBOutlet UIButton *codeBtn;
@property (weak, nonatomic) IBOutlet UILabel *markLable;

@end

@implementation GYLockListTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    GYLockListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:lockListCellIdentifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] firstObject];
    }
    
    return cell;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    self.routeBtn.layer.cornerRadius = 15;
    self.applyBtn.layer.cornerRadius = 15;
    self.codeBtn.layer.cornerRadius = 15;
}


/**
 按钮点击事件

 @param sender <#sender description#>
 */
- (IBAction)onClick:(UIButton *)sender {
    if (sender.tag == 3) {
        //判断该锁有没有编码
        if (self.model.lockState) {
            //代表已编码
            [SVProgressHUD showInfoWithStatus:@"该锁具已编码!"];
            [SVProgressHUD dismissWithDelay:2.0];
            
            return;
        }
    }
    
    self.lockActionCallBack(sender.tag, self.model);
}


- (CGFloat)cellHeight {
    return CGRectGetMaxY(self.markLable.frame);
}

- (void)setModel:(GYLock *)model {
    _model = model;
    
    self.areaLable.text = model.areaName;
    self.latLable.text = [NSString stringWithFormat:@"%f -- %f",model.lat,model.lng];
    
}

@end
